#!/usr/bin/env python
#! -*- coding: utf-8 -*-

import pymongo

def data_query():
    py_client = pymongo.MongoClient(
        host="10.10.2.149",
        username="opsmart",
        password="q1w2e3r4",
        authSource='neikong',
        authMechanism='SCRAM-SHA-1'
    )
    db = py_client.neikong

    medicine_obj = db.SFLZ_StdMedicine.find({"obsoleted":False},no_cursor_timeout = True)

    id_new = []
    num = 1
    for obj in medicine_obj:
        delet_flag = 0
        for i in id_new:
            if obj["name"] == i["name"] and obj["approval_no"] == i["approval_no"] and obj["approval_no"] == i["approval_no"] and obj["specification"] == i["specification"]:
                db.SFLZ_StdMedicine.delete_one({'_id' : obj["_id"]})
                print "删除数据: ",obj["name"], "id: ", obj["_id"]
                delet_flag = 1
        if delet_flag == 0:
            id_new.append(obj)
        print "当前数量：", num
        num += 1
    medicine_obj.close()

def main():
    data_query()

main()